<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>购物车计算</title>
    <link type="text/css" rel="stylesheet" href="index.css">
</head>
<body>
<div id="app">
    <!--处理购物车的显示-->
    <div v-if="books.length > 0 ">
        <table>
            <caption>书籍购物车计算</caption>
            <thead>
            <tr>
                <th>编号</th>
                <th>书籍名称</th>
                <th>书籍价格</th>
                <th>购买数量</th>
                <th>操作</th>

            </tr>
            </thead>

            <tbody>
            <tr v-for="(item, index) in books">
                <td>{{ item.id }}</td>
                <td>{{ item.name }}</td>
                <td>{{ item.price }}</td>
                <td style="width: 140px">
                    <button v-on:click="books[index].count--" v-bind:disabled="books[index].count <=1" >-</button>
                    <span style="width: 40px">{{ item.count }}</span>
                    <button v-on:click="books[index].count++">+</button>
                </td>
                <td>
                    <button style="background-color: red" v-on:click="books.splice(index, 1)">delete</button>
                </td>
            </tr>
            <tr>
                <td colspan="3">总价：</td>
                <td colspan="2">{{ total }}</td>
            </tr>
            </tbody>


        </table>
    </div>
    <div v-else>
        <h2>购物车为空！</h2>
    </div>
</div>

<script type="module" src="index.js"></script>
</body>
</html>